#include <iostream>
#include <stdio.h>
#include <fstream>
#include <streambuf>
#include <assert.h>
using namespace std;

long searchchar(string insertfile110){//搜查字符个数（避开空格和换行）
    char outc1;
    long numberofchar=0;
    ifstream insertfile;
    insertfile.open(insertfile110.data());//连接文件流对象与文件
    assert(insertfile.is_open());//停止程序运行输出错误消息（如出现错误）
    while (!insertfile.eof())
    {
        insertfile>>outc1;
        numberofchar++;
    }
    if(numberofchar>=2) numberofchar--;
    insertfile.close();//关闭文件
    return numberofchar;
}

long searchword(string insertfile110){//搜寻单词个数（避开-单词）
    char outc2;
    long numberofword=0;
    int verb111=0;
    ifstream insertfile;
    insertfile.open(insertfile110.data());
    assert(insertfile.is_open());
    insertfile >> noskipws;
    while (!insertfile.eof())
    {
        insertfile>>outc2;
        if(65<=outc2&&outc2<=122&&verb111==0){
            verb111++;
        }
        if(verb111!=0&&outc2<65&&outc2!=45){
            numberofword++;
            verb111=0;
        }
        if(verb111!=0&&outc2>122){
            numberofword++;
            verb111=0;
        }
    }
    if(verb111!=0) numberofword++;
    insertfile.close();
    return numberofword;
}
long searchsentence(string insertfile110){//搜寻句子个数（搜寻.或；出现个数）
    char ouct3;
    long numberofsentence=0;
    int verb111=0;
    ifstream insertfile;
    insertfile.open(insertfile110.data());
    assert(insertfile.is_open());
    insertfile >> noskipws;
    while (!insertfile.eof())
    {
        insertfile>>ouct3;
        if(65<=ouct3&&ouct3<=122&&verb111==0){
            verb111++;
        }
        if(verb111!=0&&ouct3==59){
            numberofsentence++;
            verb111=0;
        }
        if(verb111!=0&&ouct3==46){
            numberofsentence++;
            verb111=0;
        }

    }
    if(verb111!=0) numberofsentence++;
    insertfile.close();
    return numberofsentence;
}

void helpserve()
{
    cout<<"error";
}

int main(int argc,char *argv[])
{
    string char1="-c",word1="-w",sentence1="-s";//-c字符数 -w单词数 -s句子数  
    string symb1=argv[2];
    string symb0=argv[1];
    int sumsss=argc;
    if(sumsss<3){
        helpserve();
    }
    else{

        if(symb0==char1){
            printf("%ld个字符\n",searchchar(symb1));
        }
        else if(symb0==word1){
            printf("%ld单词\n",searchword(symb1));
        }
        else if(symb0==sentence1){
            printf("%ld句子\n",searchsentence(symb1));
        }

    }
    return 0;
}

